﻿@{
    ViewData["Title"] = "添加新闻";
    Layout = "_layout";
    var NewTypes = ViewBag.NewTypes as List<BuyWithoutLoseMoney.Core.Models.NewsType>;
    var News = ViewBag.News as List<BuyWithoutLoseMoney.Core.Models.News>;
}
@model List<BuyWithoutLoseMoney.Core.Models.ProductType>;

    <div>
        <div class="layui-card">
            <div class="layui-card-header">添加新闻</div>
            <div class="layui-card-body">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="Title" required lay-verify="required" placeholder="请输入新闻标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">副标题</label>
                        <div class="layui-input-block">
                            <input type="text" name="SubTitle" required lay-verify="required" placeholder="请输入新闻副标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">新闻内容</label>
                        <div class="layui-input-block">
                            <textarea name="Content" placeholder="请输入新闻内容" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">发布时间</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="CreateTime" id="ID-laydate-type-datetime1" placeholder="请选择上架时间">
                        </div>
                    </div>、
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">作者</label>
                        <div class="layui-input-block">
                            <input type="text" name="Author" required lay-verify="required" placeholder="请输入作者" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">新闻分类</label>
                        <div class="layui-input-block">
                            <select name="NewsTypeId" lay-verify="required">
                                @foreach (var item in NewTypes)
                                {
                                    <option value="@item.Id">@item.Name</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">状态</label>
                        <div class="layui-input-block">
                            <input type="radio" name="Status" value="1" title="发布" checked>
                            <input type="radio" name="Status" value="2" title="未发布">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="addForm">立即提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
  @section Scripts{
    <script>
        layui.use(["form", 'layer', 'laydate'], function () {
            var form = layui.form;
            var $ = layui.$;
            var layer = layui.layer;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#ID-laydate-type-datetime1',
                type: 'datetime'
            });
            //提交
            form.on('submit(addForm)', function (data) {
                $.post("/admin/new/create", data.field, function (res) {
                    if (res.isSuccess) {
                        layer.msg(res.msg, function () {
                            parent.window.location.href = "/admin/new/index";
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                });
                return false;
            });
        })
    </script>
    }